package com.lahuan.demo.controller;


import org.springframework.web.bind.annotation.*;

import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import lombok.RequiredArgsConstructor;
import com.lahuan.common.Result;
import com.lahuan.demo.service.Test1Service;
import com.lahuan.demo.entity.Test1;
import javax.validation.Valid;

/**
 * <p>
 * test1 控制器
 * </p>
 * @author lahuan
 * @since 2021-12-04
 */
@RequiredArgsConstructor
@RestController
@Slf4j
@Api(value = "test1", tags = "test1接口")
@RequestMapping("/demo/test1")
public class Test1Controller {

    private final Test1Service test1Service;

    @ApiOperation(value = "获取test1分页列表",notes="获取test1分页列表")
    @GetMapping("")
    public  Result<Page<Test1>> test1List(Page< Test1> page, Test1 query) {
        return Result.ok(test1Service.page(page, Wrappers.query(query)));
    }

    @ApiOperation(value = "根据id获取test1",notes="根据id获取test1")
    @ApiImplicitParam(name = "id", value = "test1id", required = true, dataType = "Long ")
    @GetMapping("/{id}")
    public Result<Test1> test1GetById(@PathVariable Long id) {
        return Result.ok(test1Service.getById(id));
    }

    @ApiOperation(value = "添加test1",notes="新增test1")
    @PostMapping("")
    public Result<Boolean> test1Save(@RequestBody @Valid  Test1 test1) {
        return Result.ok(test1Service.save(test1));
    }

    @ApiOperation(value = "修改test1",notes="根据id修改test1")
    @PutMapping("/{id}")
    public Result<Boolean> test1Update(@RequestBody @Valid  Test1 test1, @PathVariable Long id) {
        test1.setId(id);
        return Result.ok(test1Service.updateById(test1));
    }

    @ApiOperation(value = "删除test1",notes="根据id删除test1")
    @ApiImplicitParam(name = "id", value = "test1id", required = true, dataType = "Long ")
    @DeleteMapping("/{id}")
    public Result<Boolean> test1Delete(@PathVariable Long id) {
        return Result.ok(test1Service.removeById(id));
    }


}
